// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/resolved/pass.h>
#include <cantor/proto/resolved.pb.h>

#include "context.h"

namespace cantor::resolved {
    template<class Sub>
    class ResolvedVisitorBase {
    public:
        ResolvedVisitorBase(google::protobuf::Message *m) : node(m) {
        }

        ResolvedVisitorBase(google::protobuf::Message *m, int i) : node(m), index(i) {
        }

        virtual ~ResolvedVisitorBase() {
        }

        turbo::Status accept(PassBase *pass) {
            pass->context->push_path(Sub::TAG, index, node);
            auto s = static_cast<Sub *>(this)->accept_impl(pass);
            pass->context->pop_path();
            return s;
        }

        virtual turbo::Status accept_impl(PassBase *pass) = 0;

        google::protobuf::Message *node{nullptr};
        int index{-1};
    };
} // namespace cantor::resolved
